package com.tea.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tea.Model.Notice;
import com.tea.Model.dto.NoticeAddDTO;
import com.tea.Model.dto.NoticeUpdateDTO;
import com.tea.service.NoticeService;
import com.tea.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/notice")
public class NoticeController {
    
    @Resource
    private NoticeService noticeService;
    
    @GetMapping("/active")
    public Result<List<Notice>> getActiveNotices() {
        return noticeService.getActiveNotices();
    }
    
    @GetMapping("/list")
    public Result<Page<Notice>> getNoticeList(
            @RequestParam(defaultValue = "1") int current,
            @RequestParam(defaultValue = "10") int size) {
        return noticeService.getNoticeList(current, size);
    }
    
    @GetMapping("/{id}")
    public Result<Notice> getNoticeById(@PathVariable Long id) {
        return noticeService.getNoticeById(id);
    }
    
    @PostMapping("/add")
    public Result<String> addNotice(@Valid @RequestBody NoticeAddDTO noticeAddDTO) {
        return noticeService.addNotice(noticeAddDTO);
    }
    
    @PutMapping("/update")
    public Result<String> updateNotice(@Valid @RequestBody NoticeUpdateDTO noticeUpdateDTO) {
        return noticeService.updateNotice(noticeUpdateDTO);
    }
    
    @DeleteMapping("/{id}")
    public Result<String> deleteNotice(@PathVariable Long id) {
        return noticeService.deleteNotice(id);
    }
}